/*
 * WtWord.cs - Wordtrainer
 * 
 * Copyright (C) 1998-2007 Markus Kilås
 *               
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Authors:
 *   Markus Kilås <markus@markuspage.com>
 *
 */

using System;

namespace WtSharp
{
	
	
	public class WtWord : IComparable
	{	
		private string m_sWordF;
		private string m_sWordT;
		private string[] m_WordsF;
		private string[] m_WordsT;
		private int m_Type;
		private bool m_bUsed;
		private int m_nWrong;
		
		public WtWord(string sWordF, string sWordT) : this(sWordF, sWordT, 0)
		{
		}
		
		public WtWord(string sWordF, string sWordT, int Type)
		{
			initialize();
			WordF = sWordF.Trim();
			WordT = sWordT.Trim();
			m_Type = Type;
			m_nWrong = 0;
		}
		
		protected void initialize()
		{
			m_bUsed = false;
		}
		
		public string WordF
		{
			get
			{
				return m_sWordF;
			}
			set
			{
				m_sWordF = value;
				m_WordsF = SplitWords(m_sWordF);
			}
		}
		
		public string WordT
		{
			get
			{
				return m_sWordT;
			}
			set
			{
				m_sWordT = value;
				m_WordsT = SplitWords(m_sWordT);
			}
		}
		
		public string[] WordsF
		{
			get
			{
				return m_WordsF;
			}
		}
		
		public string[] WordsT
		{
			get
			{
				return m_WordsT;
			}
		}
		
		public int Type
		{
			get
			{
				return m_Type;
			}
			set
			{
				m_Type = value;
			}
		}
		
		public bool Used
		{
			get
			{
				return m_bUsed;
			}
		}
		
		public override string ToString() {
			return m_sWordF + " - " + m_sWordT + " ("+m_Type+")";
		}
		
		public int Wrong
		{
			get
			{
				return m_nWrong;
			}
			set
			{
				m_nWrong = value;
			}
		}
		
		public int CompareTo(object o)
		{
			if(!(o is WtWord))
				return 2;
			WtWord other = (WtWord)o;
			int res = m_sWordF.CompareTo(other.m_sWordF);
			if(res == 0)
				res = m_sWordT.CompareTo(other.m_sWordT);
			return res;
		}
		
		private string[] SplitWords(string word)
		{
			string[] words = word.Split(',');
			for(int i = 0; i < words.Length; i++)
				words[i] = words[i].Trim();
			return words;
		}
	}
}
